import {Script, Word, Dictionary,OpCode} from './compiler.ts';

export class CachedDictionary implements Dictionary {
    cache=new Map<string, Word|undefined>();
    constructor(private toCache:Dictionary) {}
    async lookup(word:string):Promise<Word|undefined> {
        if (this.hasCache(word)) return this.cache.get(word);
        var ret = await this.toCache.lookup(word);
        this.cache.set(word, ret);
        return ret;
    }
    hasCache(word:string):boolean {
        return this.cache.has(word);
    }
}